package com.spring.example;

import com.spring.example.mapper.UserMapper;
import com.spring.example.mybatis.utils.ZhzSession;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.TransactionFactory;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Slf4j(topic = "e")
public class Example2 {
	public static void main(String[] args) {
//		DataSource dataSource =null;
//		TransactionFactory transactionFactory = null;
//		Environment environment =
//				new Environment("development", transactionFactory, dataSource);
//		Configuration configuration = null;
//		configuration.addMapper(null);
//		SqlSessionFactory sqlSessionFactory =
//				new SqlSessionFactoryBuilder().build(configuration);
//		SqlSession sqlSession = sqlSessionFactory.openSession();
		//得到一个对象
		//返回一个代理对象
		//内部使用了JDK动态代理技术 完成了 UserMapper接口的代理
		//  Proxy.newProxyInstance();
//		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
//		mapper.queryall();

//
//		NxSession nxSession = new NxSession();
//
//		//返回一个代理对象
//		//特定的代理对象 改代理对象必须实现了clazz接口
//
//		UserMapper mapper = (UserMapper) nxSession.getProxyMapper(UserMapper.class);
//		//这个代理对象当中的queryall方法能够完成数据库的查询
//		mapper.queryall();
//		System.out.println(mapper);




		//自己手写
		ZhzSession session=new ZhzSession();
		//返回一个特定的代理对象,该代理对象必须实现clazz接口
		UserMapper userMapper=(UserMapper)session.getProxyMapper(UserMapper.class);
		//代理对象能够完成数据库的查询
		userMapper.queryall();
	}
}
